package com.coderman.infosys.auth.domain.bo.role;

import java.util.List;
import java.util.stream.Collectors;

import com.coderman.infosys.auth.domain.bo.BaseBOV2;
import com.coderman.infosys.plat.auth.common.enums.StatusEnum;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

/**
* @Description:角色组类
* @Author:shenshuai
* @CreateTime:2022-01-02 15:27:38
* @version v1.0
*/
@Data
@ToString
public class RoleGroupBO extends BaseBOV2 {

   public RoleGroupBO(){}

   public RoleGroupBO(String groupCode){
      this.groupCode = groupCode;
   }
   /** 主键ID **/
   private Long id;

   /** 角色组名称 **/
   private String groupName;

   /** 角色组编码 **/
   private String groupCode;

   /** 组内角色列表 **/
   private List<RoleBO> roleList;

   /** 角色状态 **/
   private Integer status;


   public void disable(){
      this.status = StatusEnum.DISABLE.getStatus();
   }

   public void enable(){
      this.status = StatusEnum.ENABLE.getStatus();
   }



   /**
    * 根据实体标示构建RoleGroupBO对象
    * @param roleGroupCode
    * @return
    */
   public static RoleGroupBO ofIdentifer(String roleGroupCode){
      return new RoleGroupBO(roleGroupCode);
   }


   /**
    * 将list转换成string 字符串拼接形式，存数据库
    * @return
    */
   public String getRoleCodeArrStr(){
      if(this.roleList == null || this.roleList.isEmpty()){
         return "";
      }
      List<String> roleCodeList = this.roleList.stream().map(RoleBO::getRoleCode).collect(Collectors.toList());
      return StringUtils.join(roleCodeList, ",");
   }


}